﻿namespace System {
	static class Random {
		static method nextInt(a=null, b=null) {
			_0 = @system_random_nextint;
			argmatch(NULL, NULL) {
				return _0;
			} else argmatch(INT, NULL) {
				if (a > 0) {
					return _0 % a;
				}
			} else argmatch(INT, INT) {
				return _0 % (b - a) + a;
			} 
			throw new IllegalArgumentException();
		}

		static method nextBool() {
			return @system_random_nextfloat < 0.5;
		}

		static method nextFloat() {
			return @system_random_nextfloat;
		}

		static method shuffle(list) {
			length = list.length;
			for (i = 0; i < list.length; ++i) {
				j = Random.nextInt(length, null);
				t = list[i];
				list[i] = list[j];
				list[j] = t;
			}
		}
	}
}